import { AppModel } from '../../../../model/AppModel';
import { createUIWidgetMenu } from '../BlockPackage'

export default {

    category: Blockly.Categories.operators ,
    color: [
        Blockly.Colours.operators.primary,
        Blockly.Colours.operators.secondary,
        Blockly.Colours.operators.tertiary
    ] ,

    previousStatement: false ,
    nextStatement: false ,
    hat: false ,

    extensions: ['colours_operators', 'output_number'] ,

    init(model: AppModel) {
        this.appendDummyInput()
            .appendField("RGB颜色 红")
            .appendField("绿")
        this.appendValueInput("red")
        this.appendValueInput("blue")
            .appendField("蓝")
        this.appendValueInput("green")
        Blockly.Extensions.apply("output_number", this)
    } ,

    run (args: any, util: any, runtime: any) {
        let red = parseInt(args.red)
        if(isNaN(red))
            red = 0
        let green = parseInt(args.green)
        if(isNaN(green))
            green = 0
        let blue = parseInt(args.blue)
        if(isNaN(blue))
            blue = 0
        let css = '#' + (((red&255)<<16 | (green&255)<<8 | (blue&255)) .toString(16) .padStart(6,"0"))
        console.log(css)
        return css
    } ,

    coder: {
        JavaScript(block: any) {
            return ""
        }
    }
}
